<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box{width:100px;height:100px;background: red;position: absolute;left:0;top:0px;}
    </style>
</head>
<body>

    <div class="box"></div>

</body>
<script>

    var oBox = document.querySelector(".box")

    var speed = 100;

    document.onkeydown = function(eve){
        var e = eve || window.event;
        var code = e.keyCode || e.which;
        if(code === 37){
            oBox.style.left = oBox.offsetLeft - speed + "px";
        }
        if(code === 38){
            oBox.style.top = oBox.offsetTop - speed + "px";
        }
        if(code === 39){
            oBox.style.left = oBox.offsetLeft + speed + "px";
        }
        if(code === 40){
            oBox.style.top = oBox.offsetTop + speed + "px";
        }
    }



    
</script>
</html>